package com.labtalk.admin.service.impl;

import com.labtalk.admin.mapper.UserMapper;
import com.labtalk.admin.pojo.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserEntity user = userMapper.selectOne(username);
        UserDetails userDetails = User.withUsername(user.getUsername())
                .password(user.getPassword())
                .authorities("admin")
                .build();
        return userDetails;
    }
}
